import { createRouter, createWebHistory } from 'vue-router'
import store from '@/store'
const Login = () => import('@/views/login/LoginPage.vue')
const Resetpassword = () => import('@/views/login/ResetPassword.vue')

const Layout = () => import('@/views/layout/Layout.vue')
const Welcome = () => import('@/views/Welcome.vue')

const ReviewHrInfo = () => import('@/views/review/ReviewHrInfo.vue')
const ReviewSeekerInfo = () => import('@/views/review/ReviewSeekerInfo.vue')
const HrAccount = () => import('@/views/account/HrAccount.vue')
const SeekerAccount = () => import('@/views/account/SeekerAccount.vue')
const JobData = () => import('@/views/data/JobData.vue')
const ResumeData = () => import('@/views/data/ResumeData.vue')
const Feedback = () => import('@/views/feedback/Feedback.vue')
const White = () => import('@/views/White.vue')

const routes = [
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/resetpassword',
    name: 'resetpassword',
    component: Resetpassword
  },

  {
    path: '/',
    name: 'layout',
    component: Layout,
    children: [
      {
        path: '/index',
        name: '',
        component: Welcome
      },
      {
        path: '/white',
        name: 'white',
        component: White
      },
      {
        path: '/reviewseeker',
        component: ReviewSeekerInfo
      },
      {
        path: '/reviewhr',
        component: ReviewHrInfo
      },
      {
        path: '/hraccount',
        component: HrAccount
      },
      {
        path: '/seekeraccount',
        component: SeekerAccount
      },
      {
        path: '/jobdata',
        component: JobData
      },
      {
        path: '/resumedata',
        component: ResumeData
      },
      {
        path: '/feedback',
        component: Feedback
      }
    ]
  },

]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  if (to.path == '/login' || to.path == '/register' || to.path == '/resetpassword') {
    next()
  } else {
    if (store.state.UserInfo.userInfo == null || store.state.UserInfo.userInfo.email == null) {
      next('/login')
      return
    } else {
      next()
      return
    }
  }

})

export default router
